package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/odd-even-linked-list/
 * @create 2025/9/11 22:25
 * @since JDK17
 */

public class Solution18 {
    public ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode odd = head, p = odd, even = head.next, q = even;
        while (q != null) {
            p.next = q.next;
            if (q.next != null) {
                p = q.next;
                q = q.next = p.next;
            } else {
                break;
            }
        }
        p.next = even;

        return odd;
    }
}
